#include<iostream>
#include<list>


using namespace std;

void show_info(const std::list<int> &list)
{
    cout << "size:"<<list.size()<<endl;
}
void show_list(const std::list<int> &list)
{
    cout << "list:";
    for(auto &item:list)
    {
        cout << item << " ";
    }
    cout << endl;
}
void test_init()
{
    std::list<int> list1{1,2,3,4,5,6,7,8,9,10};
    show_info(list1);
    show_list(list1);
    /*
        size:10
        list:1 2 3 4 5 6 7 8 9 10
    */

    std::list<int> list2(list1.begin(),list1.end());
    show_info(list2);
    show_list(list2);
    /*
        size:10
        list:1 2 3 4 5 6 7 8 9 10 
    */

    std::list<int> list3;
    show_info(list3);
    show_list(list3);
    /*
        size:0
        list:
    */
    
    std::list<int> list4(10,100);
    show_info(list4);
    show_list(list4);
    /*
        size:10
        list:100 100 100 100 100 100 100 100 100 100
    */
    
    std::list<int> list5(10);
    show_info(list5);
    show_list(list5);
    /*
        size:10
        list:0 0 0 0 0 0 0 0 0 0 
    */
}

void test_access()
{   
    std::list<int> list{1,2,3,4,5,6,7,8,9,10};
#if 1
    /* front and back return reference of first and last element*/
    cout << "front:" << list.front()<<", back: "<< list.back() << endl;
    list.front() = 0;
    list.back() = 0;
    cout << "front:" << list.front()<<", back: "<< list.back() << endl;
#endif
}

void test_modify()
{ 
    std::list<int> list{1,2,3,4,5,6,7,8,9,10};
#if 0
    /* push_back and push_front add element to the end and front of list*/
    list.push_back(11);
    list.push_front(0);
    show_list(list);
    /*
        list:0 1 2 3 4 5 6 7 8 9 10 11
    */
    list.pop_back();
    show_list(list);
    /*  list:0 1 2 3 4 5 6 7 8 9 10*/
    list.pop_front();
    show_list(list);
    /* list:1 2 3 4 5 6 7 8 9 10 */
#endif

#if 0 
    list.emplace_front(0);
    show_info(list);
    show_list(list);

    list.emplace_back(11);
    show_info(list);
    show_list(list);

    list.emplace(list.end(),100);
    show_info(list);
    show_list(list);

    auto iter = list.begin();
    std::advance(iter,1);
    list.emplace(iter, 200);   /* multi parameters*/
    show_info(list);
    show_list(list);

#endif

#if 1  
    auto it = list.erase(list.begin());
    //list.erase(list.end());  --> error
    show_info(list);
    show_list(list);
    if (it == list.end()) {
        cout << "point to list end" << endl;
    }

    auto iter = list.end();
    //std::advance(iter,3);// --->loop at begin+2
    //list.erase(list.end(),iter);  --> error
    std::advance(iter,-3);
    it = list.begin();

#endif

}

int main()
{
    //test_init();
    //test_access();
    test_modify();
    return 0;
}